{extend name="common/main"/}

{block name="body"}
    <!-- 标题栏 -->
    <div class="main-title">
        <h2>管理字段</h2>
    </div>
    <div class="button-box row clearfix">

        <div class="col-md-6">
            <a class="btn btn-info {if !check_auth('admin/Field/editField')}disabled{/if}" href="{:url('editField',['group_id' => $group_id])}" target-form="ids">
                新增
            </a>
            <button class="btn btn-danger ajax-post confirm {if !check_auth('admin/Field/setFieldStatus')}disabled{/if}" url="{:url('setFieldStatus', ['status' => -1])}" target-form="ids">
                删除
            </button>
        </div>
    </div>
    <!-- 数据列表 -->
    <div class="data-table with-padding">
        <table class="table table-bordered table-striped user-table muu-table">
            <thead>
            <tr>
                <th class="row-selected row-selected">
                    <input type="checkbox" class="check-all" id="check-all">
                    <label for="check-all"></label>
                </th>
                <th>字段名称</th>
                <th>字段描述</th>
                <th>是否公开</th>
                <th>是否必填</th>
                <th>排序</th>
                <th>表单类型</th>
                <th>创建时间</th>
                <th>状态</th>
                <th class="">操作</th>

            </tr>
            </thead>
            <tbody>
            {notempty name="list"}
            {volist name="list" id="vo"}
                <tr>
                    <td>
                        <input class="ids" id="field-{$vo.id}" type="checkbox" name="ids[]" value="{$vo.id}"/>
                        <label for="field-{$vo.id}"></label>
                    </td>
                    <td>{$vo.field_name}</td>
                    <td>{$vo.field_alias}</td>
                    <td>{$vo.visiable}</td>
                    <td>{$vo.required}</td>
                    <td>{$vo.sort}</td>
                    <td>{$vo.form_type}</td>
                    <td>{$vo.create_time|time_format}</td>
                    <td>{$vo.status|get_status_title}</td>
                    <td>
                        <a class="btn btn-sm btn-primary" href="{:url('admin/field/editField',['id'=>$vo['id']])}" >编辑</a>
                        <a href="{:url('setFieldStatus', ['ids' => $vo['id'],'status'=> -1])}" data-confirm="确认执行删除操作？" class="btn btn-sm btn-danger ajax-post">
                            <i class="fa fa-times"></i> 删除
                        </a>
                    </td>
                </tr>
            {/volist}
            {else/}
                <td colspan="13" class="text-center">
                    空空如也~
                </td>
            {/notempty}
            </tbody>
        </table>

    </div>
{/block}

{block name="script"}
    <script>
    $(function(){
    //排序
        $('[data-role="select_text"]').change(function(){
            var url = window.location.href;
            var query = $('.select_box').find('select').val();
            if (url.indexOf('?') > 0) {
                if(url.indexOf('order') > 0){    
                    url = changeURLArg(url,'order',query);
                }else{
                    url += '&' + 'order='+query;
                }
            } else {
                url += '?' + 'order='+query;
            }
            window.location.href = url;
        });

        //设置url中参数值
        function changeURLArg(url,arg,arg_val){
            var pattern=arg+'=([^&]*)';
            var replaceText=arg+'='+arg_val; 
            if(url.match(pattern)){
                var tmp='/('+ arg+'=)([^&]*)/gi';
                tmp=url.replace(eval(tmp),replaceText);
                return tmp;
            }else{ 
                if(url.match('[\?]')){ 
                    return url+'&'+replaceText; 
                }else{ 
                    return url+'?'+replaceText; 
                } 
            }
        }

        //搜索功能
        $("#search").click(function () {
            var url = $(this).attr('url');
            var query = $('.search-form').find('input').serialize();
            query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g, '');
            query = query.replace(/^&/g, '');
            if (url.indexOf('?') > 0) {
                url += '&' + query;
            } else {
                url += '?' + query;
            }
            window.location.href = url;
        });
        //回车搜索
        $(".search-input").keyup(function (e) {
            if (e.keyCode === 13) {
                $("#search").click();
                return false;
            }
        });
    });
    </script>
{/block}